IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spTdoctran_RetrieveAll')
	BEGIN
		PRINT 'Dropping Procedure spTdoctran_RetrieveAll'
		DROP  Procedure  spTdoctran_RetrieveAll
	END

GO

PRINT 'Creating Procedure spTdoctran_RetrieveAll'
GO

CREATE Procedure spTdoctran_RetrieveAll
	(
		@d_id varchar(50) = null, 
		@d_datetime DateTime = null, 
		@d_status varchar(50) = null, 
		@d_descrip varchar(254) = null, 
		@d_releasetype varchar(50) = null, 
		@d_releasereason varchar(500) = null, 
		@d_primaryattorney varchar(100) = null, 
		@d_secondaryattorney varchar(100) = null, 
		@d_releasedate DateTime = null, 
		@d_returndate DateTime = null, 
		@d_primaryattorneyletterreference varchar(50) = null, 
		@d_secondaryattorneyletterreference varchar(50) = null, 
		@d_trackingnumber varchar(100) = null, 
		@d_user varchar(50) = null, 
		@d_workstation varchar(50) = null, 
		@d_uniqueid uniqueidentifier = null
	)
AS
    /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 8/25/2007	Initial version created
    ------------------------------------------------------------------------------
    */
	
	SET NOCOUNT ON
	
	-- Retrieve the relevant records
	SELECT  *
	FROM	Tdoctran
	
	WHERE	(@d_id IS NULL OR Tdoctran.d_id LIKE @d_id + '%')
	  AND	(@d_datetime IS NULL OR Tdoctran.d_datetime = @d_datetime)
	  AND	(@d_status IS NULL OR Tdoctran.d_status LIKE @d_status + '%')
	  AND	(@d_descrip IS NULL OR Tdoctran.d_descrip LIKE @d_descrip + '%')
	  AND	(@d_releasetype IS NULL OR Tdoctran.d_releasetype LIKE @d_releasetype + '%')
	  AND	(@d_releasereason IS NULL OR Tdoctran.d_releasereason LIKE @d_releasereason + '%')
	  AND	(@d_primaryattorney IS NULL OR Tdoctran.d_primaryattorney LIKE @d_primaryattorney + '%')
	  AND	(@d_secondaryattorney IS NULL OR Tdoctran.d_secondaryattorney LIKE @d_secondaryattorney + '%')
	  AND	(@d_releasedate IS NULL OR Tdoctran.d_releasedate = @d_releasedate)
	  AND	(@d_returndate IS NULL OR Tdoctran.d_returndate = @d_returndate)
	  AND	(@d_primaryattorneyletterreference IS NULL OR Tdoctran.d_primaryattorneyletterreference LIKE @d_primaryattorneyletterreference + '%')
	  AND	(@d_secondaryattorneyletterreference IS NULL OR Tdoctran.d_secondaryattorneyletterreference LIKE @d_secondaryattorneyletterreference + '%')
	  AND	(@d_trackingnumber IS NULL OR Tdoctran.d_trackingnumber LIKE @d_trackingnumber + '%')
	  AND	(@d_user IS NULL OR Tdoctran.d_user LIKE @d_user + '%')
	  AND	(@d_workstation IS NULL OR Tdoctran.d_workstation LIKE @d_workstation + '%')
	  AND	(@d_uniqueid IS NULL OR Tdoctran.d_uniqueid = @d_uniqueid)

	-- Return to calling method
	RETURN
GO
